<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        li {
            list-style: none;
        }

        #box {
            width: 500px;
            height: 500px;
            display: flex;
            flex-direction: column;
            margin: 100px auto 0px;




        }

        #ul {
            width: 100%;
            height: 60px;
            background-color: black;
            background-color: aliceblue;
            display: flex;
            justify-content: center;
            justify-content: center;
            align-items: center;
        }

        #ul>li {
            flex-grow: 1;
            text-align: center;
            height: 100%;
            line-height: 60px;
        }

        #ol {

            flex-grow: 1;

            justify-content: center;
            align-items: center;
            position: relative;
        }

        #ol>li {

            justify-content: center;
            align-items: center;
            height: 100%;
            width: 100%;
            position: absolute;
            top: 0px;
            left: 0px;
            font-size: 100px;
            color: white;
            display: none;
        }

        #ol>li:first-child {
            display: flex;
        }

        ul>li.active {
            background-color: rgb(194, 56, 32);
        }

        #ol>li.active {
            background-color: rgb(179, 90, 75);
        }
    </style>

</head>

<body>
    <div id="box">
        <ul id="ul">
            <li class="active">1</li>
            <li>2</li>
            <li>3</li>
        </ul>
        <ol id="ol">
            <li class="active">1</li>
            <li>2</li>
            <li>3</li>
        </ol>
    </div>
    <script>
        //获取所有的ul的li
        const tabLi = document.querySelectorAll("#ul>li");
        //获取所有的ol的li
        const contentLi = document.querySelectorAll("#ol>li");
        //遍历每一个tab li 并绑定点击事件
        tabLi.forEach((eachLi, index) => {
            // 给单个的li绑定点击事件
            eachLi.onclick = () => {

                //清除原有的ul的每一个li的样式,遍历每一个tab的li
                tabLi.forEach((tabLiStyleDel) => {
                    tabLiStyleDel.classList.remove("active");
                })

                //清除原有的ol的li样式,遍历每一个content的li
                contentLi.forEach((contentLiStyleDel) => {
                    contentLiStyleDel.style.display = "none";
                })
                //让被点击的li添加样式
                eachLi.classList.add("active");
                //让被点击的li对应的li内容出现
                contentLi[index].style.display = "flex";
                contentLi[index].classList.add("active")
            }
        })
    </script>

</body>


</html>